#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;


class Solution {
public:
    int StrToInt(string str) {
        string::iterator it = str.begin();
        if ((*it < '0' || *it >'9') && (*it != '-' && *it != '+')) {
            return 0;
        }
        int flag = 1;
        if (*it == '-') {
            flag = -1;
            it++;
        }
        else if (*it == '+') {
            flag = 1;
            it++;
        }
        int num = 0;
        while (it != str.end()) {
            if (!isdigit(*it)) {
                return 0;
            }
            num = num * 10 + (*it) - '0';
            it++;
        }
        return num * flag;
    }
};